<div class="content">
	<div class="tab_bar">
		<ul>
			<li class="tab_index" onclick="setTabContent(this);">编辑文章</li>
		</ul>
		 <button class="btn_tabbar submit_it" onclick="mySubmitForm(this);" return="article/list.do?currentPageNo=1">保 存</button>
	</div>
	
	<form id="myForm" action="article/update.do" method="post">
	<input name="id" type="hidden" value="${article.id?c}" />
	<div class="tab_content">
		<div class="tab_item tab_show"> 
			<table class="table_for_add">
				<tbody>
					<tr class="rowBgColor">
						<th width="140">所属类别：</th>
						<td> 
							<select id="categoryid" class="select_for_add" name="cid">
					  			<@categoryTree id = 0 node = -1/> 
							</select>
						</td>
					</tr>
					<tr>
						<th>文章标题： </th>
						<td><input class="input_for_add" name="title" type="text" value="${article.title!}" /></td>
					</tr>
					<tr class="rowBgColor">
						<th>文章图标： </th>
						<td><input class="input_for_add" name="icon" type="text" value="${article.icon!}"  /></td>
					</tr>
			 		<tr>
						<th>内容类型： </th>
						<td>
							<#if article.type == 0>
							<input id="statistics_1" name="type" type="radio" value="0" checked="checked" /><label for="statistics_1">&nbsp;HTML&nbsp; &nbsp;</label>
							<input id="statistics_2" name="type" type="radio" value="1" /><label for="statistics_2">&nbsp;text/markdown&nbsp; &nbsp;</label>
							<#else>
							<input id="statistics_1" name="type" type="radio" value="0" /><label for="statistics_1">&nbsp;HTML&nbsp; &nbsp;</label>
							<input id="statistics_2" name="type" type="radio" value="1" checked="checked"  /><label for="statistics_2">&nbsp;text/markdown&nbsp; &nbsp;</label>
							</#if>
							<span class="tip_text">切换类型将会清空内容哦!</span>
						</td>
						<td></td>
					</tr>
					<tr>
				    	<th>文章内容：</th>
						<td></td>
					</tr>
				    <tr>
						<td colspan="2">
							<script type="text/plain" id="mushroomeditor" name="content" style="height:350px;;"></script>
							<textarea id="mrcmsContent" style="display:none"><#if article.type == 0>${article.content!}<#else>${article.orginal!}</#if></textarea>
						</td>
					</tr>
					<tr class="rowBgColor">
						<th>文章关键字：</th>
						<td><input class="input_for_add" name="keywords" type="text" value="${article.keywords!}"  /></td>
					</tr>
					<tr>
						<th>文章描述：</th>
						<td><textarea class="textarea_for_add" name="description">${article.description!}</textarea></td>
					</tr> 
					<tr class="rowBgColor">
						<th>文章作者：</th>
						<td><input class="input_for_add" name="author" type="text" value="${article.author!}" /></td>
					</tr> 
					<tr>
						<th>文章状态：</th>
						<td>
							<#if article.status == 1>
								<input id="status_1" name="status" type="radio" value="1" checked="checked" /> <label for="status_1">发布</label> 
								<input id="status_0" name="status" type="radio" value="0" /> <label for="status_0">草稿</label>
							<#else>
								<input id="status_1" name="status" type="radio" value="1"/> <label for="status_1">发布</label> 
								<input id="status_0" name="status" type="radio" value="0" checked="checked"/> <label for="status_0">草稿</label>
							</#if>
						</td>
					</tr> 
				</tbody>
			</table>
		</div>
	</div>
	</form> 
</div>

<script type="text/javascript">
$(function(){
	$("input[name='type']").click(function(){
 		editor.execCommand( 'source');
		if($(this).val() == 1){
 	 		editor.setDisabled();
		}else{ 
			editor.setEnabled();
		}
	 	editor.setContent('');
	});
	
	
	
	if(window.editor !=null){
		window.editor.destroy();
	}
	 //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    window.editor = UE.getEditor('mushroomeditor');
 	
	window.editor.ready(function(){
		$("#title").focus();//纠正显示
		<#if article.type == 1> 
 			editor.execCommand( 'source');
	 		editor.setDisabled();
		</#if> 
		editor.setContent($("#mrcmsContent").val()); 
	});
});

function mySubmitForm(obj){
 	window.editor.sync();//手动提交需要手动同步编辑器数据 
	submitActionForm(obj);
} 


//设置栏目ID
var cid = '${article.cid?c}';
$("#categoryid").attr('value',cid);
</script>



<#macro categoryTree id node>
	<#local temp = node + 1 />
	<#list categorys as x>
	  	<#if id = x.pid>
	  	<option value="${x.id?c}"><#list 0..temp as i> &nbsp; &nbsp; </#list>├ ${x.name!}</option>
	    <@categoryTree id = x.id node=temp/>
      	</#if>
	</#list> 
</#macro>